/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.pressa.server;

import com.pressa.server.service.ACKandSaveReportThread;
import com.pressa.server.service.UDPService;
import com.pressa.server.ui.UI_Server;
import javax.swing.UIManager;

/**
 *
 * @author Lucas Borri (lborri@pressa.com.ar)
 */
public class Main {

    public static void main(String[] args) {
        //---Colocamos el Look and Feel
        try {
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
        } catch (Exception e) {
            e.printStackTrace();
        }
        int numReporte = 0;
               
        //---Inicialización de la Ventana principal
        UI_Server serverWindow = new UI_Server();
        serverWindow.setVisible(true);

        try {
            UDPService packetService = new UDPService();
            boolean flag = false;
            String received = null;
            while (!flag) { //Ciclo repetitivo
                Thread.sleep(250);
                received = packetService.receivePacket("4008");
                if (received.contains(">RFM")) {                                //Si recibe un comando FM llama al thread
                    serverWindow.setGarminLog(numReporte + ": RX: " + received);
                    ACKandSaveReportThread save = new ACKandSaveReportThread(received);
                    save.start();
                    numReporte++;
                }
            }
            Thread.sleep(250);
        } catch (Exception e) {
        }
    }
}
